const express = require("express");
const router = require("./router");
const fs = require("fs"); // 文件处理
const https = require("https");
const bodyParser = require("body-parser");
const cors = require("cors");

const app = express();

app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use("/", router);

const privateKey = fs.readFileSync("./https/front.webhlx.site.key");
const pem = fs.readFileSync("./https/front.webhlx.site.pem");
credentials = {
  key: privateKey,
  cert: pem,
};
const httpsServer = https.createServer(credentials, app);

const server = app.listen(5000, function () {
  const { address, port } = server.address();
  console.log("http://localhost:%s", port);
});

httpsServer.listen(18082, function () {
  const { address, port } = httpsServer.address();
  console.log("https ", address, port); // https://localhost:18082
});
